import React, { Component } from 'react';
import { Button, Modal, Form, Drawer, Alert, Divider, Tabs } from 'antd';
import '@/assets/css/settings';
import * as ProductionOrderService from '../../../axios/ProductionOrder'
import * as SpecialMachineService from '../../../axios/SpecialMachine'
import * as DingTalkSettingsService from '../../../axios/DingTalkSettings'
import * as FileService from '../../../axios/File'
import { BasicLayoutSearch } from '../../../components/BasicLayout';
import { BasicPagination, isInvalidObject, TableCustomize, openSuccessModal, openModalMessage, compareDate, compareString, compareNum } from '../../../components/TableCustomize'
import { approvalList } from '../../../utils/global';
import SearchForm from './SearchForm';
import AddForm from './AddForm';
import { withRouter } from 'react-router';
import Details from './Details';
import { withPermission } from '../../../components/withpermission'
const CreateButton = withPermission(Button, 'plus')
const DeleteButton = withPermission(Button, 'minus')
const PrintButton = withPermission(Button, 'printer')
const DownLoadButton = withPermission(Button, 'download')

const { TabPane } = Tabs;
class SpecialMachine extends Component {
  constructor(props) {
    super(props);
    this.newTabIndex = 0;
    this.state = {
      dataSource: [],
      advanced: false,
      approvalList: [],

      searchItem: {
        department: localStorage.getItem('workShop')
      },
      pageSize: 10,
      pageNum: 1,
      total: 0,
      columns: [
        {
          title: '顺序号',
          dataIndex: 'orderNo',
          width: 200,
          sorter: (a, b) => compareNum(a.orderNo, b.orderNo)
        },
        {
          title: '机型',
          width: 180,
          dataIndex: 'model',
          sorter: (a, b) => compareString(a.model, b.model),
        },
        {
          title: '批号',
          dataIndex: 'batchNo',
          width: 100,
          sorter: (a, b) => compareString(a.batchNo, b.batchNo)
        },

        {
          title: '安排日期',
          width: 150,
          dataIndex: 'arrangeTime',
          sorter: (a, b) => compareDate(a.arrangeTime, b.arrangeTime)
        },
        {
          title: '交机日期',
          width: 150,
          dataIndex: 'firstDeliveryTime',
          ellipsis: true,
          sorter: (a, b) => compareDate(a.firstDeliveryTime, b.firstDeliveryTime)
        },
        {
          title: '出机日期',
          width: 150,
          dataIndex: 'firstOutputTime',
          ellipsis: true,
          sorter: (a, b) => compareDate(a.firstOutputTime, b.firstOutputTime)
        },
        {
          title: '特供内容',
          width: 150,
          editable: true,
          ellipsis: true,
          dataIndex: 'specialContent',
          sorter: (a, b) => compareString(a.specialContent, b.specialContent)
        },
        {
          title: '创建人',
          width: 100,
          dataIndex: 'userName',
          sorter: (a, b) => compareString(a.userName, b.userName)
        },
        {
          title: '修改日期',
          width: 150,
          dataIndex: 'updateTime',
          ellipsis: true,
          sorter: (a, b) => compareDate(a.updateTime, b.updateTime)
        },
        {
          title: '审批状态',
          width: 100,
          dataIndex: 'processInstanceStatus',
          sorter: (a, b) => compareString(a.processInstanceStatus, b.processInstanceStatus),
          render: (text) => {
            let a = this.state.approvalList.find(item => item.id == text)
            return a?.value
            // return a.id == '0' ? <span style={{ color: '#d9d9d9' }}>{a.value}</span>
            //   : a.id == '1' ? <span style={{ color: '#ffc440' }}>{a.value}</span>
            //     : a.id == '2' ? <span style={{ color: '#1e8e3e' }}>{a.value}</span>
            //       : a.id === '3' ? <span style={{ color: '#1890ff' }}>{a.value}</span> : a.value
          }
        },
        {
          title: '操作',
          width: 240,
          fixed: 'right',
          dataIndex: 'opts',
          render: (text, record) => <>
            <a onClick={() => this.add(record)}>查看</a>
            <Divider type='vertical' />
            <a onClick={() => this.createForm(1, record)}>编辑</a>
            <Divider type='vertical' />
            <a onClick={() => this.createForm(2, record)}>上传</a>
            <Divider type='vertical' />
            {
              record.processInstanceStatus !== 1 && record.processInstanceStatus !== 2 && record.processInstanceId ? < a onClick={() => this.examineAndApprove(record)}>发起审批</a> : <a onClick={() => this.anewGain(record)}>重新获取结果</a>
            }

          </>
        }
      ],
      selectedRows: [],
      selectedRowKeys: [],
      panes: [],
      activeKey: 'top',
      drawerVisible: false,
      drawerTitle: '新增生产安排表',
      formData: {},
      fileList: [],
      batchNoList: [],
      loading_submit: false,
      filePathList: [],
      deleteList: [],  // 删除图片
      printArr: [],  // 打印图片
      addFrom: [],  // 车间数据
    };

  }

  componentDidMount() {
    this.init()
    this.setState({ approvalList })
    if (this.props.location.data) {
      this.setState({ searchItem: this.props.location.data }, this.fetch)
    } else {
      this.fetch()
    }

    // console.log(localStorage.getItem('SpecialMachine_activeKey'));
    // console.log(localStorage.getItem('SpecialMachine_panes'));
    // if (localStorage.getItem('SpecialMachine_activeKey') || localStorage.getItem('SpecialMachine_panes')) {
    //   const { panes } = this.state;
    //   let activeKey = JSON.parse(localStorage.getItem('SpecialMachine_activeKey'))
    //   panes.push(JSON.parse(localStorage.getItem('SpecialMachine_panes')))
    //   this.setState({ panes, activeKey });
    //   localStorage.removeItem('SpecialMachine_activeKey')
    //   localStorage.removeItem('SpecialMachine_panes')
    // }
    // // 查询批号
    // SpecialMachineService.findPlanAll({ pageNum: 1, pageSize: 1000 }).then(res => {
    //   this.setState({ loading: false })
    //   if (res.data.data.code !== 200) {
    //     openModalMessage('warning', res.data.data.msg)
    //     return
    //   }
    //   this.setState({ batchNoList: res.data.data.data })
    // }).catch(err => {
    //   openModalMessage('error', err.message)
    // })

  }
  componentWillUnmount() {
    this.setState = () => {
      return;
    };
  }

  // 初始化查询
  init = () => {
    // 派工班组查询
    ProductionOrderService.findGroupAll().then(res => {
      const addFrom = res.data.data
      // console.log(addFrom, '派工班组查询');
      this.setState({ addFrom });
    })

    // 查询批号
    SpecialMachineService.findPlanAll({ pageNum: 1, pageSize: 1000 }).then(res => {
      this.setState({ loading: false })
      if (res.data.data.code !== 200) {
        openModalMessage('warning', res.data.data.msg)
        return
      }
      this.setState({ batchNoList: res.data.data.data })
    }).catch(err => {
      openModalMessage('error', err.message)
    })
  }

  //初始化加载数据
  fetch = (pageNum = 1, pageSize = 100) => {
    this.setState({ loading: true })
    const { searchItem } = this.state
    searchItem.pageNum = pageNum
    searchItem.pageSize = pageSize
    // let str = ''
    // for (var key in searchItem) {
    //   if (searchItem[key] || searchItem[key] === 0) {
    //     str += `&${key}=${searchItem[key]}`
    //   }
    // } 

    SpecialMachineService.findSpecialProvision(searchItem).then(res => {
      this.setState({ loading: false })
      if (res.data.data.code !== 200) {
        openModalMessage('warning', res.data.data.msg)
        return
      }
      this.setState({ dataSource: res.data.data.data, total: res.data.data.total, pageNum, pageSize })
    }).catch(err => {
      openModalMessage('error', err.message)
    })
  }
  // 导出
  downloadFather = () => {
    const { selectedRows } = this.state;
    if (selectedRows.length) {
      this.setState({ downloadLoading: true });
      SpecialMachineService.exportSpecialOfferInformationManageExcel({ list: selectedRows }).then(res => {
        //设置下载文件类型为xlsx 不同的类型type也不一样，创建URL对象
        let url = window.URL.createObjectURL(new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))
        // 创建A标签
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        // 设置的下载文件文件名
        const fileName = decodeURI('特供信息表');
        // 触发点击方法
        link.setAttribute('download', fileName)
        document.body.appendChild(link)
        link.click()
        this.setState({ downloadLoading: false })
      })
    } else {
      Modal.confirm({
        title: '默认导出数据较多，需要较长时间，确认全部导出吗？',
        onOk: async () => {
          await this.fetchAll();
          const { dataSourceAll } = this.state;
          await SpecialMachineService.exportSpecialOfferInformationManageExcel({ list: dataSourceAll }).then(res => {
            //设置下载文件类型为xlsx 不同的类型type也不一样，创建URL对象
            let url = window.URL.createObjectURL(new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))
            // 创建A标签
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            // 设置的下载文件文件名
            const fileName = decodeURI('特供信息表');
            // 触发点击方法
            link.setAttribute('download', fileName)
            document.body.appendChild(link)
            link.click()
            this.setState({ downloadLoading: false })
          })
        },
        onCancel() { }
      })
    }
  }
  // 查询所有数据，跨页全选可用
  fetchAll = async () => {
    const { searchItem, total } = this.state
    searchItem.pageNum = 1
    searchItem.pageSize = total
    let str = ''
    for (var key in searchItem) {
      if (searchItem[key] || searchItem[key] === 0) {
        str += `&${key}=${searchItem[key]}`
      }
    }
    await SpecialMachineService.querySpecialOfferManage(str).then(res => {
      if (res.data.data.code !== 200) {
        openModalMessage('warning', res.data.data.msg)
        return
      }
      const dataSourceAll = res.data.data.data
      const selectedRowKeys = dataSourceAll.map(item => item.specialProvisionId);
      this.setState({ dataSourceAll, selectedRowKeys, selectedRows: dataSourceAll })
    }).catch(err => {
      openModalMessage('error', err.message)
    })
  }
  // 选择某一行数据
  chooseRow = record => {
    let flag = true;
    let index = 0;
    this.state.selectedRowKeys.forEach((row, i) => {
      if (row == record.specialProvisionId) {
        flag = false;
        index = i;
      }
    })
    const selectedRowKeys = this.state.selectedRowKeys;
    const selectedRows = this.state.selectedRows;
    if (flag) {
      selectedRowKeys.push(record.specialProvisionId);
      selectedRows.push(record);
    } else {
      selectedRowKeys.splice(index, 1);
      selectedRows.splice(index, 1);
    }
    this.setState({ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows });
  };
  // 打开详情页
  openDetails = (record) => {
    const { searchItem } = this.state;
    const data = {}
    data.batchNo = record.batchNo
    data.procedureName = record.procedureName
    localStorage.setItem('SpecialMachine_searchItem', JSON.stringify(searchItem));
    localStorage.setItem('SpecialMachine_detailsList', JSON.stringify(data));
    this.props.history.push({ pathname: "/SpecialMachine_Details", data: { record: data, searchItem } })
  }
  loadData = (row, dataSource) => {

    row.userId = localStorage.getItem("userId")
    row.pictureId = []

    this.updateSpecialProvision(row)

    // console.log(row, dataSource)
  }
  // 点击查询
  handleSearch = value => {
    console.log(value)
    if (value.firstDeliveryDate && value.firstDeliveryDate.length === 2) {
      value.firstDeliveryDateMin = value.firstDeliveryDate[0].format('YYYY-MM-DD 00:00:00')
      value.firstDeliveryDateMax = value.firstDeliveryDate[1].format('YYYY-MM-DD 23:59:59')
      delete (value.firstDeliveryDate)
    }
    if (value.firstOutputTime && value.firstOutputTime.length === 2) {
      value.firstOutputTimeMin = value.firstOutputTime[0].format('YYYY-MM-DD 00:00:00')
      value.firstOutputTimeMax = value.firstOutputTime[1].format('YYYY-MM-DD 23:59:59')
      delete (value.firstOutputTime)
    }
    if (value.updateDate && value.updateDate.length === 2) {
      value.updateDateMin = value.updateDate[0].format('YYYY-MM-DD 00:00:00')
      value.updateDateMax = value.updateDate[1].format('YYYY-MM-DD 23:59:59')
      delete (value.updateDate)
    }
    this.setState({ searchItem: value }, this.fetch);
  };
  // 高级查询
  onHandleAdvanced = () => {
    this.setState({ advanced: !this.state.advanced })
  }
  onChangeTabs = activeKey => {
    this.setState({ activeKey });
  };

  onEdit = (targetKey, action) => {
    this[action](targetKey);
  };
  // 新增查看页面，新增多页签
  add = (record) => {
    const { panes } = this.state;
    const activeKey = record.specialProvisionId.toString()
    let a = panes.find(item => item.key == activeKey)
    if (!a) {
      panes.push({ title: `${record.model}-查看特供信息`, content: <Details formData={record} key={activeKey} />, key: activeKey });
    }
    this.setState({ panes, activeKey });
    // localStorage.setItem('SpecialMachine_activeKey', JSON.stringify(activeKey));
    // localStorage.setItem('SpecialMachine_panes', JSON.stringify(panes));

  };
  // 删除多页签
  remove = targetKey => {
    let { activeKey } = this.state;
    let lastIndex;
    this.state.panes.forEach((pane, i) => {
      if (pane.key === targetKey) {
        lastIndex = i - 1;
      }
    });
    const panes = this.state.panes.filter(pane => pane.key !== targetKey);
    if (panes.length && activeKey === targetKey) {
      if (lastIndex >= 0) {
        activeKey = panes[lastIndex].key;
      } else {
        activeKey = 'top';
      }
    }
    if (panes.length === 0) {
      activeKey = 'top';
    }
    this.setState({ panes, activeKey });
  };
  // 打开新增、修改侧滑框
  createForm = async (type, data) => {
    console.log(data);
    this.setState({ loading: true })
    let fileList = []
    if (type === 1 || type === 2) {
      let fileIdList = data.pictureId;
      if (fileIdList && fileIdList.length) {
        for (var item of fileIdList) {
          if (item) {
            await FileService.queryFileId(item).then(res => {
              if (res.data.code === 200) {
                fileList.push(res.data && res.data.data ? res.data.data : [])
              }
            })
          }
        }
      }
    }
    let fileListNew = []
    fileListNew = fileList.map(items => {
      return {
        uid: items.fileId,
        name: items.fileName,
        status: 'done',
        url: items.tomcatPath,
      }
    })
    this.setState({
      formType: type,
      formData: data,
      drawerVisible: true,
      drawerTitle: type === 1 ? '编辑生产工作表' : type === 2 ? '上传' : '新增生产工作表',
      filePathList: fileListNew,
      fileList: fileList,
      deleteList: [],
      loading: false
    })
  }
  // 新增、修改保存
  onHandleOk = () => {
    const { formType, fileList, deleteList } = this.state;
    console.log(fileList, deleteList);
    const fileListOld = [];
    const fileListNew = [];
    for (var key in fileList) {
      if (typeof (fileList[key].uid) === 'number') {
        fileListOld.push(fileList[key].uid);
        fileList.slice(key, 1);
      } else if (typeof (fileList[key].uid) === 'string') {
        fileListNew.push(fileList[key]);
      }
    }
    console.log(fileListNew, 'fileListNew');
    console.log(fileListOld, 'fileListOld');
    let filePathList = [];
    this.formDrawer.validateFields(async (err, value) => {
      if (err) return;
      this.setState({ loading_submit: true });
      if (deleteList.length) {
        // 根据picture_id删除特供机图片
        SpecialMachineService.deleteSpecialPicture(deleteList).then(res => {
          if (res.data.code !== 200) {
            openModalMessage('warning', res.data.msg);
            return;
          }
        }).catch(err => {
          openModalMessage('error', err.message);
          return;
        })
      }

      if (fileListNew.length) {
        // 上传文件
        for (let i = 0; i < fileListNew.length; i++) {
          filePathList.push(await this.uploadFile(fileListNew[i]))
        }
        this.setState({ loading_submit: false })
        console.log(filePathList, 'filePathList')
      }
      console.log(value, filePathList);
      value.firstOutputTime = value.firstOutputTime.format('YYYY-MM-DD HH:MM:SS');
      value.firstDeliveryTime = value.firstDeliveryTime.format('YYYY-MM-DD HH:MM:SS');
      value.userId = localStorage.getItem('userId')

      !value.orderNo && delete (value.orderNo)
      !value.specialProvisionId && delete (value.specialProvisionId)

      // 上传文件
      if (formType === 2) {
        if (filePathList.length) {
          // await SpecialMachineService.addSpecialPicture({ pictureId: [...filePathList, ...fileListOld], ...value }).then(res => {
          await SpecialMachineService.addSpecialPicture({ pictureId: [...filePathList], ...value }).then(res => {
            this.setState({ loading_submit: false });
            if (res.data.code !== 200) {
              openModalMessage('warning', res.data.msg);
              return;
            }
            openSuccessModal(res.data.msg);
            this.handleCancel();
          }).catch(err => {
            this.setState({ loading_submit: false });
            openModalMessage('error', err.message);
            return;
          })
          return
        }
        this.handleCancel();
      }
      // 编辑
      if (formType === 1) {
        // value.pictureId = [...filePathList, ...fileListOld]
        value.pictureId = [...filePathList]
        await this.updateSpecialProvision(value)
      }
      // 新增
      if (formType === 0) {
        // value.pictureId = [...filePathList, ...fileListOld]
        value.pictureId = [...filePathList]
        console.log(value, '新增******************');
        await SpecialMachineService.addSpecialProvision(value).then(res => {
          this.setState({ loading_submit: false })
          if (res.data.code !== 200) {
            openModalMessage('warning', res.data.msg);
            return;
          }
          openSuccessModal(res.data.msg);
          this.handleCancel();
        }).catch(err => {
          this.setState({ loading_submit: false });
          openModalMessage('error', err.message);
          return;
        })
      }
    })
  }

  // 编辑、修改
  updateSpecialProvision = async (value) => {
    console.log(value, '修改******************');
    await SpecialMachineService.updateSpecialProvision(value).then(res => {
      this.setState({ loading_submit: false })
      if (res.data.code !== 200) {
        openModalMessage('warning', res.data.msg);
        return;
      }
      openSuccessModal(res.data.msg);
      this.handleCancel();
    }).catch(err => {
      this.setState({ loading_submit: false });
      openModalMessage('error', err.message);
      return;
    })
  }

  // 上传文件到文件服务
  uploadFile = async (data) => {
    let result = {}
    await FileService.uploadFile(data).then(res => {
      console.log(res)
      if (res.data.code !== 200) {
        openModalMessage('warning', res.data.msg);
        return;
      }
      result = res.data.data.id
    }).catch(err => {
      openModalMessage('error', err.message);
      return;
    })
    return result
  }
  // 删除文件服务中的文件
  onRemoveFile = async (data) => {
    const { deleteList } = this.state
    await FileService.deleteFile(data.uid).then(res => {
      console.log(res)
      if (res.data.code !== 200) {
        openModalMessage('warning', res.data.msg);
        return;
      }
      this.setState({ deleteList: [...deleteList, data.uid] })
    }).catch(err => {
      openModalMessage('error', err.message);
      return;
    })
  }

  // 摧毁侧滑框
  handleCancel = () => {
    this.formDrawer && this.formDrawer.resetFields();
    this.setState({
      drawerVisible: false,
      formData: {},
      fileList: [],
      filePathList: [],
      loading_submit: false
    });
    this.fetch(this.state.pageNum, this.state.pageSize);
  }
  // 删除
  deleteDataSource = () => {
    const { selectedRows } = this.state
    if (!selectedRows || !selectedRows.length) {
      openModalMessage('warning', '请选择要删除的数据！');
      return;
    }
    let arr = []
    selectedRows.map(item => {
      arr.push(item.specialProvisionId)
    })
    let data = {
      "specialProvisionId": arr,
      "userId": localStorage.getItem('userId')
    }
    const that = this;
    Modal.confirm({
      title: '提示',
      content: '确认要删除所选数据吗？',
      onOk: async () => {
        await SpecialMachineService.deleteSpecialProvision(data).then(res => {
          if (res.data.code !== 200) {
            openModalMessage('warning', res.data.msg);
            return;
          }
          openSuccessModal(res.data.msg);
          that.fetch();
        }).catch(err => {
          openModalMessage('error', err.message);
          return;
        })
      }
    })

  }

  print = async () => {
    const { selectedRows } = this.state
    if (!selectedRows || !selectedRows.length) {
      openModalMessage('warning', '请选择要打印的数据！');
      return;
    }
    console.log(selectedRows, 'selectedRows ---- print');
    let arr = []
    selectedRows.map(item => {
      arr.push(...item.pictureId)
    })

    let fileList = []
    for (var item of arr) {
      if (item) {
        await FileService.queryFileId(item).then(res => {
          if (res.data.code === 200) {
            fileList.push(res.data && res.data.data ? res.data.data : [])
          }
        })
      }
    }
    console.log(fileList, 'fileList');
    const that = this;
    that.printAll(fileList)
  }

  // 打印
  printAll = (fileList) => {
    debugger
    let printArr = []
    for (let item of fileList) {
      if (item.fileFormat && item.fileFormat != 'pdf') {
        printArr.push(item)
      } else if (item.fileFormat == 'pdf') {
        openModalMessage('warning', '暂不支持 PDF 文件批量打印');
      }
    }
    this.setState({ printArr }, () => {
      setTimeout(() => {
        var printInnerHTML = window.document.getElementById('billDetails_all').innerHTML;
        window.document.body.innerHTML = printInnerHTML
        var printImg = window.document.getElementsByClassName('printImg');
        var loading_img = false;
        if (printImg[0].offsetHeight === 0) {
          loading_img = false;
          return;
        } else {
          loading_img = true
        }
        if (loading_img) {
          clearTimeout(t_img);
          window.print();
          window.location.reload();
        } else {
          var t_img = setTimeout(() => {
            this.printAll(fileList)
          }, 500);
        }
      }, 1000)
    })
  }
  // 发起审批
  examineAndApprove = (data) => {
    let item = `orderNo=${data.orderNo}&userId=${localStorage.getItem('userId')}`
    DingTalkSettingsService.sendSpecialReportDD(item).then((value) => {
      if (value.data.code !== 200) {
        openModalMessage('warning', value.data.msg);
        return
      }
      this.fetch()
      openSuccessModal(value.data.msg)
    })
  }
  // 重新获取结果
  anewGain = (data) => {
    let datas = `processInstanceId=${data.processInstanceId}`
    DingTalkSettingsService.reacquire(datas).then((value) => {
      if (value.data.code !== 200) {
        openModalMessage('warning', value.data.msg);
        return
      }
      this.fetch()
      openSuccessModal(value.data.msg)
    })

  }
  resetForm = () => {
    this.formSearch && this.formSearch.resetFields();
    this.setState({
      searchItem: {
        department: localStorage.getItem('workShop')
      }
    }, this.fetch);
  }
  render() {
    const { addFrom, printArr, batchNoList, approvalList, loading, dataSource, advanced, columns, pageNum, pageSize, total, selectedRowKeys, downloadLoading, searchItem, drawerVisible, drawerTitle, formData, formType, loading_submit, filePathList } = this.state;
    const rowSelection = {
      type: 'checkbox',
      selectedRowKeys: selectedRowKeys,
      onChange: (selectedRowKeys, selectedRows) => {
        this.setState({
          selectedRows: selectedRows,
          selectedRowKeys: selectedRowKeys,
        })
      },
      onSelectAll: (selected, selectedRows, changeRows) => {
        const keys = [... this.state.selectedRowKeys];
        const rows = [... this.state.selectedRows];
        if (selected) {
          changeRows.forEach(row => {
            if (isInvalidObject(keys.find(key => key === row.specialProvisionId))) {
              keys.push(row.specialProvisionId);
              rows.push(row);
            }
          })
        } else {
          changeRows.forEach(row => {
            keys.splice(keys.indexOf(row.specialProvisionId), 1);
            rows.splice(rows.indexOf(row), 1);
          })
        }
        this.setState({ selectedRows: rows, selectedRowKeys: keys })
      }
    }

    return (
      <div>
        <BasicLayoutSearch>
          <SearchForm onSearch={this.handleSearch}
            onClick={this.onHandleAdvanced}
            advanced={advanced}
            searchItem={searchItem}
            resetForm={this.resetForm}
            statusList={approvalList}
            addFrom={addFrom}
            ref={node => (this.formSearch = node)}
          />
        </BasicLayoutSearch>
        <Tabs tabBarExtraContent={(
          <div className='mydiv'>
            {
              this.state.activeKey == 'top' ? [
            <CreateButton key='1' onClick={() => this.createForm(0, {})} icon="plus" />,
            <DeleteButton key='2' onClick={() => this.deleteDataSource()} icon="minus" />,
            <PrintButton key='3' onClick={() => {/* this.print() */ }} icon="printer" />,
            <DownLoadButton key='4' onClick={() => { this.downloadFather() }} icon="download" loading={downloadLoading} />

            // <Button key={0} type="primary" onClick={() => this.createForm(0, {})} icon="plus">新增</Button>,
            // <Button key={1} type="primary" onClick={() => this.deleteDataSource()} icon="minus">删除</Button>,
            // <Button key={2} type="primary" onClick={() => {/* this.print() */ }} icon="printer">打印</Button>,
            // <Button type="primary" key={7} onClick={() => { this.downloadFather() }} icon="download" loading={downloadLoading}>导出</Button>,
              ] : []}
          </div>
        )}
          hideAdd
          className="layout-model"
          onChange={this.onChangeTabs}
          activeKey={this.state.activeKey}
          type="editable-card"
          onEdit={this.onEdit}>
          {/* <div><Icon type='table' /><span>特供机信息管理</span></div> */}
          <TabPane tab={'特供机信息管理'} key="top" closable={false}>
            <Alert message={<div>已选择<span style={{ color: '#fd1818', margin: '0 3px' }}>{selectedRowKeys.length}</span>项</div>} type="info" showIcon style={{ marginBottom: 15 }} />
            <TableCustomize
              columns={columns}
              rowKey={(record) => record.specialProvisionId}
              dataSource={dataSource}
              pagination={false}
              loading={loading}
              allowRowEdit={true}
              allowDrafting={true}
              rowSelection={rowSelection}
              onRow={(record, rowKey) => ({
                onClick: this.chooseRow.bind(this, record, rowKey)
              })}
              rowClassName={(record, index) => {
                return (['editable-row', index % 2 === 0 ? 'editable-row' : 'editable-row12'])
              }}
              allowEditable={this.loadData}
            />
            <BasicPagination pageNum={pageNum} pageSize={pageSize} total={total} loadData={this.fetch} />
          </TabPane>
          {this.state.panes.map(pane => (
            <TabPane tab={pane.title} key={pane.key}>
              {pane.content}
            </TabPane>
          ))}
        </Tabs>

        <Drawer
          width={400}
          visible={drawerVisible}
          title={drawerTitle}
          onClose={this.handleCancel}
          maskClosable={false}
          destroyOnClose
        >
          <AddForm
            formData={formData}
            onOk={this.onHandleOk}
            ref={node => (this.formDrawer = node)}
            onClose={this.handleCancel}
            saveFileList={(value) => this.setState({ fileList: value })}
            onRemoveFile={this.onRemoveFile}
            formType={formType}
            fileList={filePathList}
            batchNoList={batchNoList}
          />
          <div
            style={{
              position: 'absolute',
              right: 0,
              bottom: 0,
              width: '100%',
              borderTop: '1px solid #e9e9e9',
              padding: '10px 16px',
              background: '#fff',
              textAlign: 'right',
            }}
          >
            <Button onClick={this.handleCancel} style={{ marginRight: 10 }}>{'取消'}</Button>
            <Button type="primary" onClick={this.onHandleOk} loading={loading_submit}>
              {'确认'}
            </Button>
          </div>

        </Drawer>

        {/* 打印 */}
        <div id={"billDetails_all"} style={{ display: 'none' }}>
          {
            printArr && printArr.map((item, index) => {
              return item.fileFormat == 'pdf' ?
                // <iframe src={item.tomcatPath} height={400} width={'100%'} className="imgPrint"></iframe>
                null
                :
                <div key={index}>
                  <img alt='logo' className={'printImg'} src={item.tomcatPath} />
                </div>
            })
          }
        </div>

      </div>
    );
  }
}
export default Form.create()(withRouter(SpecialMachine));